LiveCode Android Setup For PC & Mac, 3/2015
(print for reference during setup)

* DOWNLOAD & INSTALL LIVECODE SOFTWARE
http://downloads.livecode.com/livecode/
1) Download & install the newest STABLE version of LiveCode. LC v6.7.x and v7.0.x are parallel developments. The 7.0 series has unicode, is slower, has much larger file size, and more bugs. Do not use DP (development) or RC (release candidates) versions.
[Recommend] newest LC v6.7.x stable version.
2) LiveCode allows multiple version installs. Ensure you develop with the newest LC version as Android conflicts and bugs are promised a next-version fix. The version # is displayed in the LiveCode menu bar.

Android lessons from RunRev installing java & android:
http://lessons.runrev.com/s/lessons/m/2571/l/27385-how-do-i-become-an-android-developer-on-a-pc
http://lessons.runrev.com/m/2571/l/27389-how-do-i-become-an-android-developer-on-a-mac

Android help with SDK Manager and virtual devices from developer.android:
http://developer.android.com/tools/help/sdk-manager.html
http://developer.android.com/tools/devices/managing-avds.html

* DOWNLOAD & INSTALL JAVA SOFTWARE
http://www.oracle.com/technetwork/java/javase/downloads/index.html
1) Click the first "JAVA" button. Accept the license agreement for Java SE Developer Kit 8u31
2) Download Java software for your computer platform. Windows x86 = Win32. "jdk-8u31-windows-i586.exe".
3) Install before installing android software. Accept all defaults. Java jdk installed to: C:\Program Files\Java\jdk1.8.0_31. (Document your specific jdk for later use.)

* DOWNLOAD & INSTALL ANDROID SOFTWARE
http://developer.android.com/sdk/index.html

LC v6.7.2 stable / 7.0.2 stable are compatible through Android 5.0.1(21) & BuildTools(21.1.2)

===== INSTALLATION STEPS PC =====
1) Download Android SDK Tools at the bottom of the Android web page, not the larger complex Android Studio at the top of the page. Accept the license agreement.
2) Install Android SDK Tools (internet required). Accept all defaults. At end of install, check to start SDK Manager. Android sdk installs to: C:\Users\<userName>\AppData\Local\Android\android-sdk, but can be installed to any location.
3) Launch error. Must point SDK Manager to Java jdk by defining a Java_Home variable. Start > computer > system properties > advanced system settings > environment variables. Create new name and variable: Java_Home, C:\Program Files\Java\jdk1.8.0_31   (use "\").
4) Launch SDK Manager from Start. Manager auto-checks newest Tools: Tools 24.0.2, PlatformTools 21, BuildTools 21.1.2, and auto-checks newest Android: 5.0.1(21) and Extras: Android Support Library and Google USB Driver. BuildTools are downward/backward compatible, so BuildTools(21.1.2) are good for Android 5.0.1(21) and all lower Android versions.
5) Check Android 2.2(8) required by LiveCode to build Android apps. Uncheck 2.2(8) component: samples.

* [Option A] If testing stacks on Android physical device only, no emulator: uncheck all newest Android, 5.0.1(21).
* [Option B] If testing on physical device and emulator: check any other Android versions. [Recommend] Android 4.2.2(17), uncheck 4.2.2(17) components: sample, Intel. Check all Extras. Compile on lowest version to support, test on highest version for compatibility.

6) Click Install at bottom right of window, accept license agreement, click Install.
7) Uncheck Updates/New at bottom left. The SDK Manager collapses to display only what is installed. [doesn't stay checked.]
8) Launch LiveCode: Edit > Preferences > Mobile Support.
9) At location for Android development SDK root, click the "..." button and navigate to C:\Users\<userName>\AppData\Local\Android\android-sdk, [or your file path], hilite folder "android-sdk", click Select Folder button.
(AppData is a hidden file. F1 help > type hidden file > click show hidden files > click open folder options > view > under hidden files & folders select show hidden files, apply. Navigate to sdk. When done, change back to hide hidden files.)
10) Your Java path should show: C:\Program Files\Java\jdk1.8.0_31. (Or your specific jdk version).
===== READY FOR ANDROID DEVELOPMENT =====

* CONFIGURE ANDROID EMULATOR
Creating a virtual device:
http://www.techotopia.com/index.php/Creating_an_Android_Virtual_Device_(AVD)

1) Start > SDK Manager > Tools > Manage AVD > Device Definitions.
2) Choose a pre-defined virtual device definition, Create AVD. [Nexus 7 1200x1920]
3) If making Name change: no "( )" parenthesis, no special characters, no spaces allowed.
4) Target: 4.2.2(17). [Not 2.2(8). Not 2.3.3(10) if PC doesn't support hardware virtualization.]
5) CPU/ABI: ARM EABI [Not Intel Atom which requires HAXM emulator accelerator which won't install on PC if it doesn't support hardware virtualization.]
6) Hardware Keyboard: uncheck for native keyboard, check for physical keyboard.
7) Skin: No Skin.
8) Memory Options: default 2048 [1024 to 750 if PC has 1G RAM.]
9) SD Card: leave blank.
10) Snapshot: uncheck if PC has 1G RAM, GPU: uncheck if PC has 1G RAM. (Both speed up SDK Manager launch, can't use simultaneously.)
11) Click OK or returnKey to build AVD, can take up to 10 min with no progress bar. Dialog eventually appears indicating build complete. (If crash/freeze: ctrl-shift-esc for Task Manager, select SDK Manager, end task. May have to restart PC.)

* [Option] GENYMOTION + VIRTUALBOX ALTERNATIVE FASTER EMULATOR
Genymotion setup info:
http://livecode.com/blog/2014/10/15/turbo-charging-the-android-emulator/
Genymotion ARM translation installer:
http://forum.xda-developers.com/showthread.php?t=2528952
1) Download ARM translation installer zip, drag to genymotion emulator, follow prompts, quit emulator, relaunch emulator.

* LAUNCH ANDROID EMULATOR
1) Start > SDK Manager > Tools > Manage AVD, select desired virtual device to launch, click Start.
2) Verify Launch Options. Use default settings, click Launch. A black emulator window appears. Within 2 to 3 min an Android logo should appear in the middle indicating emulator has fully opened. Leave the emulator running.
3) Open LiveCode project stack. File > Standalone Application Settings > General, use default settings > Android, check build for android, sign for development only, allow external storage. Use other default settings. A stack may require additional unique feature check-boxes. Click X close box.
4) Development > Test Target > Android emulator-5554. Selects emulator that is already running.
5) Development > Test. Launches stack into emulator.

* CONFIGURE ANDROID PHYSICAL DEVICE
1) Only Windows requires the SDK Manager Extras component: USB device driver. This should have been auto-checked at original Android install.
2) On device home screen, Menu > Applications > Development, enable USB debugging. [refer to device manual/website.]
3) Connect device via USB to computer.
4) Android device should now be accessible from within LiveCode project stack. Development > Test Target, select device. Development > Test. [If device is not recognized, a driver from the device website may need to be installed. Refer to device manual.]

* CREATE A SELF-SIGNED CERTIFICATE KEY (required for submission to an app store)
Keytool is a key generation application in the Java install. Access using a Mac Terminal or a Windows Command Prompt.
1) Start > type Command Prompt, click first link to open. Must navigate to C:\Program Files\Java\jdk1.8.0_31\bin. [or your jdk version]
2) Change Directory (filepath). Type: cd c:\program files\java\jdk1.8.0_31\bin [returnKey]
3) Type: keytool [returnKey] Keytool commands should appear.
4) Generate Key Pair Self-Signed Certificate. Type: keytool -genkeypair -keyalg RSA -validity 1100 [returnKey] (1100 = 3yrs, 1850 = 5yrs), follow prompts.
Keystore password: <KeystorePassword> [returnKey] Typed passwords are not displayed, must be >= 6 chars, cursor does not move.
Re-enter keystore password: <KeystorePassword> [returnKey]
First and last name: <YourFirstName LastName>
Name of organization unit: <Name>
Name of organization: <Name>
City: <City>
State Full Name: <State>
Two-Letter Country: US
Display of info (if correct): yes
KeyPassword (if the same as KeystorePassword): [returnKey]
* [Option] List Keystore Contents. Type: keytool -list -v [returnKey]
Enter keystore password: <KeystorePassword> [returnKey]
5) Backup the generated .keystore file & passwords. Default alias = "mykey".
6) Sign your stack with the valid working certificate key if submitting to an app store. Certificate is valid for 1100 days (3 yrs). There is no -validity <max>. After expiration, delete certificate (c:\users\<username>\.keystore) and create new. KeyAlgorithm -keyalg RSA is required by LiveCode.

Create a self-signed key, from developer.android:
http://developer.android.com/guide/publishing/app-signing.html

* DEPLOY STACK TO ANDROID
1) Adjust stack size to match aspect ratio of target device. 800/1280 & 1200/1920 = .625, .625 * stackHeight = stackWidth.
2) In a preOpenStack handler: if environment() = "mobile" then set the fullscreenMode of this stack to "exactFit"  --empty, "exactFit", "letterbox", "noBorder", "noScale", "showAll".
3) Open LiveCode project stack. File > Standalone Application Settings > General, use default settings > Android, build for android, use default settings. A stack may require additional unique feature check-boxes.
4) Choose "sign for development", or if submitting to an app store choose "sign with my key" and enter the location of your .keystore file in the Key Path field. c:\users\<username>\.keystore
5) File > Save As Standalone Application, specify a location to save your Android app.
6) Enter prompts for info required by the "my key" signing process. The .keystore alias (default alias = "mykey"), the .keystore password, and the private key password. Both signing choices create an <appname>.apk file that is self-signed and auto-aligned. An unsigned app will not install on an Android device.

* [Option] VERIFY ALIGNMENT OF .APK BEFORE UPLOAD TO APP STORE
During the signing process, LiveCode auto-aligns the app with zipalign, an application in the Android install. Access using a Mac Terminal or a Windows Command Prompt. Zipalign optimizes a signed Android .apk file to ensure uncompressed data within the .apk, such as images or raw files, are aligned. This reduces the RAM consumed running the app. An unaligned .apk file will not be accepted by Google Play.
1) Place the .apk file in a zip-compressed folder on the desktop.
2) Start > type Command Prompt, click first link to open. Must navigate to C:\Users\<UserName>\AppData\Local\Android\android-sdk\build-tools\21.1.2 [or your file path and build-tools version.]
3) Change Directory (file-path). Type: cd c:\users\<username>\appdata\local\android\android-sdk\build-tools\21.1.2 [returnKey]
4) Type: zipalign [returnKey] Zipalign commands should appear.
5) Verify Alignment. Type: zipalign -c -v 4 c:\users\<username>\desktop\<compressedfoldername>.zip [returnKey] Command Prompt should return: "Verifying alignment of..., <appname>.apk (OK -compressed), verification successful".

Verify alignment or manually align with zipalign, from developer.android:
http://developer.android.com/tools/help/zipalign.html

* ERROR DIALOGS
1) "Unable to build app for testing: could not generate package manifest."
a. Upgrade to LC >= 6.7.1 / 7.0.1 and try again. Many bug fixes have improved compatibility with Android.
b. This error can occur if icons assigned in Android standalone application settings become unlinked or are not present .
c. This error can occur if the identifier contains special characters including "-" in Android standalone application settings. All letters are OK. The identifier is how Google permanently identifies you as the developer and this app in particular. All apps you submit should use the same identifier for the first two components, the third is unique to the name of your app. The identifier is your company web domain in reverse order: the "com" first, followed by the domain name, followed by a one word app identifier: com.<yourdomainname>.<onewordappidentifier>
d. This error can occur if the version code is not a single character in Android standalone application settings. The default "1" is OK.

2) "Installation of app failed. Failure [INSTALL_FAILED_OLDER_SDK]"
This error can occur if deploying to an Android version lower than 2.2 or if Android standalone setting "Minimum Android Version" is set too high. Reset to version 2.2.

3) "Installation of app failed. Could not access the Package Manager. Is the System running?"
This error occurs launching a stack into an emulator that has not fully opened or has crashed. Ensure emulator is fully opened, waiting for Android logo to appear in black emulator window.

4) "Signing failed - private key algorithm is not compatible with signature algorithm."
This error occurs using the default key algorithm when building Android standalone, which LiveCode doesn't accept. Include -keyalg RSA in the -genkeypair statement when creating the .keystore file with keytool:
keytool -genkeypair -keyalg RSA -validity 1100 [returnKey]
